package com.levy.utils.provider;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;


/**
 *  参数管理抽象类
 * <pre>
 * -------------History------------------
 * DATE        AUTHOR        VERSION        DESCRIPTION
 * 2016年8月24日    jhj           V01.00.001		新建
 * </pre>
 * 
 * @author <a href="jiahj@asiainfo.com">贾海江</a>
 */
public abstract class ParamProvider {
	private static final Logger log = Logger.getLogger(ParamProvider.class);
	private HttpServletRequest request;
	public Map<String, Object> params = new HashMap<String, Object>();
	
	public ParamProvider(HttpServletRequest request){
		this.request = request;
	}
	
	public Object getParameter(String key) {
		Object param = this.params.get(key);
		if (null == param)
			log.warn("找不到参数：" + key);
		return param;
	}

	public void setParameter(String key, Object value) {
		if (params.containsKey(key))
			log.warn("已经有一个名为：'" + key + "'，值为：'" + this.params.get(key) + "'的参数存在。该参数将被覆盖");
		this.params.put(key, value);
		if(null!=this.request)this.request.setAttribute(key, value);
	}
	
	public void putAll(Map<String, Object> params){
		this.params.putAll(params);
	}

	public Map<String, Object> getParameters() {
		return this.params;
	}

}

